#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
const int WIDTH=10;
const int HEIGHT=20;
#define RADIUS 5;
#define SQURE 100;
enum DAY{
  MON=1,TUE,WED,THU,FRI,SAT,SUN
};

typedef struct Teacher
{
  char* name;
  int age;
} Teacher;

//由于Teacher是结构体，为了给结构体赋值，必须传二级指针，因为不能直接赋值给形参p，只能通过二级指针作为形参，再*p=temp，对p取值获取到Teacher的地址
void getTeacher(Teacher** p);


void test1();
void test2();
__attribute__((constructor)) void test3(void);
void test4();
unsigned test5(unsigned n);
int main()
{
    int arr[10];
    int i,j;
    for(i=0;i<10;i++){
      arr[i] = i+100;
    }

    for(j=0;j<10;j++){
      printf("Element[%d] = %d\n",j,arr[j]);
    }

    enum DAY day;
    day = WED;
    printf("%d\n",day);

    int a=15;
    int *p=&a;
    printf("%d,%d\n",a,*p);

    test2(1);

    test4();

    printf("test5(8)=%u\n",test5(8));

    Teacher* t= NULL;
    getTeacher(&t);
    printf("teacher age=%d\n",t->age);

    return 0;
}

void getTeacher(Teacher** p){
  //malloc 开盘了一块内存，并把指向这块内存的地址返回，需要用指针接收
  Teacher* temp = (Teacher*)malloc(sizeof(Teacher));
  temp->age=20;
  *p=temp;
}

void test1(){
  printf("this is test1\n");
}

void test2(void){
  printf("this is test2\n");
}

void test4(){
  int n=8;
  printf("8>>1=%d\n",n>>1);
  printf("8<<1=%d\n",n<<1);
}

unsigned test5(unsigned n){
  if(n == 0){
    return 1;
  }
  if(n>31){
    return 0;
  }

  unsigned val = test5(n>>1)*test5(n>>1);
  if(n&1){
    val *=2;
  }
  return val;
}

__attribute__((constructor)) void test3(void){
  printf("__attribute__((constructor)) void test3()\n");
}